<?php

/**
 * libretarecoleccion actions.
 *
 * @package    courier
 * @subpackage libretarecoleccion
 * @author     Your name here
 */
class libretarecoleccionActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Libretarecoleccions = LibretarecoleccionPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Libretarecoleccion = LibretarecoleccionPeer::retrieveByPk($request->getParameter('lre_id'));
    $this->forward404Unless($this->Libretarecoleccion);
  }

  public function executeShowDireccion(sfWebRequest $request)
  {
    $this->Cliente = ClientePeer::retrieveByPk($request->getParameter('cli_id'));
    $this->forward404Unless($this->Cliente);
  }

  public function executeNew(sfWebRequest $request)
  {
	if ($request->getParameter('cli_id') != null){
		$identificadorCliente = new Libretarecoleccion();
		$identificadorCliente->setLreCliente($request->getParameter('cli_id'));
		$this->form = new LibretarecoleccionForm($identificadorCliente);
	}
	else{
		$this->form = new LibretarecoleccionForm();
	}
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new LibretarecoleccionForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Libretarecoleccion = LibretarecoleccionPeer::retrieveByPk($request->getParameter('lre_id')), sprintf('Object Libretarecoleccion does not exist (%s).', $request->getParameter('lre_id')));
    $this->form = new LibretarecoleccionForm($Libretarecoleccion);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Libretarecoleccion = LibretarecoleccionPeer::retrieveByPk($request->getParameter('lre_id')), sprintf('Object Libretarecoleccion does not exist (%s).', $request->getParameter('lre_id')));
    $this->form = new LibretarecoleccionForm($Libretarecoleccion);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($Libretarecoleccion = LibretarecoleccionPeer::retrieveByPk($request->getParameter('lre_id')), sprintf('Object Libretarecoleccion does not exist (%s).', $request->getParameter('lre_id')));
    $Libretarecoleccion->delete();

    $this->redirect('libretarecoleccion/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Libretarecoleccion = $form->save();

      $this->redirect('libretarecoleccion/showDireccion?cli_id='.$request->getParameter('libretarecoleccion[lre_cliente]'));
    }
  }
}
